package com.example.droideep.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.droideep.R;
import com.example.droideep.common.activities.SimpleFragmentBase;

import java.util.Calendar;

import butterknife.InjectView;
import butterknife.OnClick;

/**
 * @author bri
 * @date 15-8-4.
 */
public class CalendarEventFragment extends SimpleFragmentBase {

    @InjectView(android.R.id.button1)
    Button calendar;

    @Override
    public void onResume() {
        super.onResume();
        calendar.setText("日历事件");
    }

    @Override
    protected int getContentResId() {
        return R.layout.fragment_button;
    }

    @OnClick(android.R.id.button1)
    public void calendarEvnet() {
        Calendar cal = Calendar.getInstance();
        Intent intent = new Intent(CalendarContract.ACTION_HANDLE_CUSTOM_EVENT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", cal.getTimeInMillis());
        intent.putExtra("allDay", true);
        intent.putExtra("rrule", "FREQ=YEARLY");
        intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000);
        intent.putExtra("title", "A Test Event from android app");
        startActivityForResult(intent, 111);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == 111) {
                Log.v(TAG,"aaa");
            }
        }
    }
}
